<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view/>
    </div>
  </a-config-provider>
</template>
<script>
  import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
  import enUS from 'ant-design-vue/lib/locale-provider/en_US'
  import enquireScreen from '@/utils/device'
  import { getNewJsonObject, getNewMaterial, synchronizationMaterial } from '@/api/api'
  import { getLanCode } from "@/lang"
  export default {
    data () {
      return {
        locale: getLanCode() === 'en' ? enUS : zhCN,
        onLine: navigator.onLine,
      }
    },
    created () {
      let that = this
      enquireScreen(deviceType => {
        // tablet
        if (deviceType === 0) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        // mobile
        else if (deviceType === 1) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        else {
          that.$store.commit('TOGGLE_DEVICE', 'desktop')
          that.$store.dispatch('setSidebar', true)
        }

      })
    },
    methods:{
			updateOnlineStatus(e) {
				const { type } = e;
				this.onLine = type === 'online';
        if (type == 'online') {
          getNewJsonObject().then(res=>{
            if(res.code == '200') {
              this.$message.success('上传所有到总仓成功')
            }
          })
          getNewMaterial().then(res=>{
            if(res.code == '200') {
              this.$message.success('获取总仓新商品和新调拨信息成功')
            }
          })
        } else {
          console.log("网络由异常")
        }
			},
    },
		mounted(){
      // if (navigator.onLine) {
      //   alert("正常工作");
      // } else {
      //  alert("掉线了");
      // }
			window.addEventListener('online',  this.updateOnlineStatus);// 网络由异常到正常时触发
			window.addEventListener('offline', this.updateOnlineStatus);// 网络由正常常到异常时触发
		}
  }
</script>
<style>
  #app {
    height: 100%;
  }
</style>